home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / VGAKIT50.ARJ / BANKS.ASM next >
Assembly Source File  |  1992-06-25  |  17KB  |  1,059 lines

  1.  
  2.     include    model.h
  3.     include    vesa.h
  4. ;
  5. ;    VGAKIT Version 5.0
  6. ;
  7. ;    Copyright 1988,89,90,91,92 John Bridges
  8. ;    Free for use in commercial, shareware or freeware applications
  9. ;
  10. ;    BANKS.ASM
  11. ;
  12. .data
  13.  
  14. OSEG    equ    DS:        ;segment override for variable access
  15.  
  16.     public    bankadr
  17.  
  18. if @Codesize
  19. bankadr    dw    offset _nobank
  20.     dw    seg _nobank
  21. else
  22. bankadr    dw    offset _nobank
  23. endif
  24.  
  25.     public    curbk
  26.  
  27. curbk    dw    ?
  28.  
  29.     public    vgamem,bksize
  30.  
  31. vgamem    dw    ?        ;amount of memory on VGA card in K
  32. bksize    dw    ?        ;size of memory banks in K
  33.  
  34.     public    cirrus,everex,acumos,paradise,tseng,trident,t8900
  35.     public    ativga,aheada,aheadb,oaktech,video7
  36.     public    chipstech,tseng4,genoa,ncr,compaq,s3vga,vesa
  37.  
  38. cirrus    dw    ?
  39. everex    dw    ?
  40. acumos    dw    ?
  41. paradise dw    ?
  42. tseng    dw    ?
  43. trident    dw    ?
  44. t8900    dw    ?
  45. ativga    dw    ?
  46. aheada    dw    ?
  47. aheadb    dw    ?
  48. oaktech    dw    ?
  49. video7    dw    ?
  50. chipstech dw    ?
  51. tseng4    dw    ?
  52. genoa    dw    ?
  53. ncr    dw    ?
  54. compaq    dw    ?
  55. s3vga    dw    ?
  56. vesa    dw    ?
  57.  
  58. first    dw    ?        ;flag so whichvga() is only called once
  59. retval    dw    ?        ;first return value from whichvga()
  60.  
  61. .code
  62.  
  63.     public    newbank
  64.     public    whichvga
  65.  
  66. newbank    proc            ;bank number is in AX
  67.     jmp    OSEG[bankadr]
  68.  
  69.  
  70. _tseng::            ;Tseng 3000 series
  71.     push    ax
  72.     push    dx
  73.     cli
  74.     mov    OSEG[curbk],ax
  75.     and    al,7
  76.     mov    ah,al
  77.     shl    al,1
  78.     shl    al,1
  79.     shl    al,1
  80.     or    al,ah
  81.     or    al,01000000b
  82.     mov    dx,3cdh
  83.     out    dx,al
  84.     sti
  85.     pop    dx
  86.     pop    ax
  87.     ret
  88.  
  89.  
  90. _tseng4::            ;Tseng 4000 series
  91.     push    ax
  92.     push    dx
  93.     cli
  94.     mov    OSEG[curbk],ax
  95.     mov    ah,al
  96.     mov    dx,3bfh        ;Enable access to extended registers
  97.     mov    al,3
  98.     out    dx,al
  99.     mov    dl,0d8h
  100.     mov    al,0a0h
  101.     out    dx,al
  102.     and    ah,15
  103.     mov    al,ah
  104.     shl    al,1
  105.     shl    al,1
  106.     shl    al,1
  107.     shl    al,1
  108.     or    al,ah
  109.     mov    dl,0cdh
  110.     out    dx,al
  111.     sti
  112.     pop    dx
  113.     pop    ax
  114.     ret
  115.  
  116.  
  117. _trident::            ;Trident
  118.     push    ax
  119.     push    dx
  120.     push    ax
  121.     cli
  122.     mov    OSEG[curbk],ax
  123.     mov    dx,3ceh        ;set pagesize to 64k
  124.     mov    al,6
  125.     out    dx,al
  126.     inc    dl
  127.     in    al,dx
  128.     dec    dl
  129.     or    al,4
  130.     mov    ah,al
  131.     mov    al,6
  132.     out    dx,ax
  133.  
  134.     mov    dl,0c4h        ;switch to BPS mode
  135.     mov    al,0bh
  136.     out    dx,al
  137.     inc    dl
  138.     in    al,dx
  139.     dec    dl
  140.  
  141.     pop    ax
  142.     mov    ah,al
  143.     xor    ah,2
  144.     mov    dx,3c4h
  145.     mov    al,0eh
  146.     out    dx,ax
  147.     sti
  148.     pop    dx
  149.     pop    ax
  150.     ret
  151.  
  152.  
  153. _video7::            ;Video 7
  154.     push    ax
  155.     push    dx
  156.     push    cx
  157.     cli
  158.     mov    OSEG[curbk],ax
  159.     and    ax,15
  160.     mov    ch,al
  161.     mov    dx,3c4h
  162.     mov    ax,0ea06h
  163.     out    dx,ax
  164.     mov    ah,ch
  165.     and    ah,1
  166.     mov    al,0f9h
  167.     out    dx,ax
  168.     mov    al,ch
  169.     and    al,1100b
  170.     mov    ah,al
  171.     shr    ah,1
  172.     shr    ah,1
  173.     or    ah,al
  174.     mov    al,0f6h
  175.     out    dx,al
  176.     inc    dx
  177.     in    al,dx
  178.     dec    dx
  179.     and    al,not 1111b
  180.     or    ah,al
  181.     mov    al,0f6h
  182.     out    dx,ax
  183.     mov    ah,ch
  184.     mov    cl,4
  185.     shl    ah,cl
  186.     and    ah,100000b
  187.     mov    dl,0cch
  188.     in    al,dx
  189.     mov    dl,0c2h
  190.     and    al,not 100000b
  191.     or    al,ah
  192.     out    dx,al
  193.     sti
  194.     pop    cx
  195.     pop    dx
  196.     pop    ax
  197.     ret
  198.  
  199.  
  200. _paradise::            ;Paradise
  201.     push    ax
  202.     push    dx
  203.     push    ax
  204.     cli
  205.     mov    OSEG[curbk],ax
  206.     mov    dx,3ceh
  207.     mov    ax,50fh        ;turn off write protect on VGA registers
  208.     out    dx,ax
  209.     pop    ax
  210.     mov    ah,al
  211.     mov    al,9
  212.     out    dx,ax
  213.     sti
  214.     pop    dx
  215.     pop    ax
  216.     ret
  217.  
  218. _acumos::            ;AcuMos
  219.     push    ax
  220.     push    dx
  221.     push    ax
  222.     cli
  223.     mov    OSEG[curbk],ax
  224.     mov    dx,3c4h        ;Sequencer index 6
  225.     mov    ax,1206h    ;turn off write protect on VGA registers
  226.     out    dx,ax
  227.     mov    dx,3ceh
  228.     pop    ax
  229.     mov    ah,al
  230.     mov    al,9
  231.     out    dx,ax
  232.     sti
  233.     pop    dx
  234.     pop    ax
  235.     ret
  236.  
  237.  
  238. _chipstech::            ;Chips & Tech
  239.     push    ax
  240.     push    dx
  241.     push    ax
  242.     cli
  243.     mov    OSEG[curbk],ax
  244.     mov    dx,46e8h    ;place chip in setup mode
  245.     mov    ax,1eh
  246.     out    dx,ax
  247.     mov    dx,103h        ;enable extended registers
  248.     mov    ax,0080h
  249.     out    dx,ax
  250.     mov    dx,46e8h    ;bring chip out of setup mode
  251.     mov    ax,0eh
  252.     out    dx,ax
  253.     pop    ax
  254.     mov    ah,al
  255.     mov    al,10h
  256.     mov    dx,3d6h
  257.     out    dx,ax
  258.     sti
  259.     pop    dx
  260.     pop    ax
  261.     ret
  262.  
  263.  
  264. _ativga::            ;ATI VGA Wonder
  265.     push    ax
  266.     push    dx
  267.     cli
  268.     mov    OSEG[curbk],ax
  269.     mov    ah,al
  270.     mov    dx,1ceh
  271.     mov    al,0b2h
  272.     out    dx,al
  273.     inc    dl
  274.     in    al,dx
  275.     shl    ah,1
  276.     and    al,0e1h
  277.     or    ah,al
  278.     mov    al,0b2h
  279.     dec    dl
  280.     out    dx,ax
  281.     sti
  282.     pop    dx
  283.     pop    ax
  284.     ret
  285.  
  286.  
  287. _everex::            ;Everex
  288.     push    ax
  289.     push    dx
  290.     push    cx
  291.     cli
  292.     mov    OSEG[curbk],ax
  293.     mov    cl,al
  294.     mov    dx,3c4h
  295.     mov    al,8
  296.     out    dx,al
  297.     inc    dl
  298.     in    al,dx
  299.     dec    dl
  300.     shl    al,1
  301.     shr    cl,1
  302.     rcr    al,1
  303.     mov    ah,al
  304.     mov    al,8
  305.     out    dx,ax
  306.     mov    dl,0cch
  307.     in    al,dx
  308.     mov    dl,0c2h
  309.     and    al,0dfh
  310.     shr    cl,1
  311.     jc    nob2
  312.     or    al,20h
  313. nob2:    out    dx,al
  314.     sti
  315.     pop    cx
  316.     pop    dx
  317.     pop    ax
  318.     ret
  319.  
  320.  
  321. _aheada::            ;Ahead Systems Ver A
  322.     push    ax
  323.     push    dx
  324.     push    cx
  325.     cli
  326.     mov    OSEG[curbk],ax
  327.     mov    ch,al
  328.     mov    dx,3ceh        ;Enable extended registers
  329.     mov    ax,200fh
  330.     out    dx,ax
  331.     mov    dl,0cch        ;bit 0
  332.     in    al,dx
  333.     mov    dl,0c2h
  334.     and    al,11011111b
  335.     shr    ch,1
  336.     jnc    skpa
  337.     or    al,00100000b
  338. skpa:    out    dx,al
  339.     mov    dl,0cfh        ;bits 1,2,3
  340.     mov    al,0
  341.     out    dx,al
  342.     inc    dx
  343.     in    al,dx
  344.     dec    dx
  345.     and    al,11111000b
  346.     or    al,ch
  347.     mov    ah,al
  348.     mov    al,0
  349.     out    dx,ax
  350.     sti
  351.     pop    cx
  352.     pop    dx
  353.     pop    ax
  354.     ret
  355.  
  356.  
  357. _aheadb::            ;Ahead Systems Ver A
  358.     push    ax
  359.     push    dx
  360.     push    cx
  361.     cli
  362.     mov    OSEG[curbk],ax
  363.     mov    ch,al
  364.     mov    dx,3ceh        ;Enable extended registers
  365.     mov    ax,200fh
  366.     out    dx,ax
  367.     mov    ah,ch
  368.     mov    cl,4
  369.     shl    ah,cl
  370.     or    ah,ch
  371.     mov    al,0dh
  372.     out    dx,ax
  373.     sti
  374.     pop    cx
  375.     pop    dx
  376.     pop    ax
  377.     ret
  378.  
  379.  
  380. _oaktech::            ;Oak Technology Inc OTI-067 and OTI-077
  381.     push    ax
  382.     push    dx
  383.     cli
  384.     mov    OSEG[curbk],ax
  385.     and    al,15
  386.     mov    ah,al
  387.     shl    al,1
  388.     shl    al,1
  389.     shl    al,1
  390.     shl    al,1
  391.     or    ah,al
  392.     mov    al,11h
  393.     mov    dx,3deh
  394.     out    dx,ax
  395.     sti
  396.     pop    dx
  397.     pop    ax
  398.     ret
  399.  
  400. _genoa::            ;GENOA GVGA
  401.     push    ax
  402.     push    dx
  403.     cli
  404.     mov    OSEG[curbk],ax
  405.     mov    ah,al
  406.     shl    al,1
  407.     shl    al,1
  408.     shl    al,1
  409.     or    ah,al
  410.     mov    al,6
  411.     or    ah,40h
  412.     mov    dx,3c4h
  413.     out    dx,ax
  414.     sti
  415.     pop    dx
  416.     pop    ax
  417.     ret
  418.  
  419. _ncr::                ;NCR 77C22E
  420.     push    ax
  421.     push    dx
  422.     cli
  423.     mov    OSEG[curbk],ax
  424.     mov    ah,al
  425.     mov    al,18h
  426.     mov    dx,3c4h
  427.     out    dx,ax
  428.     mov    ax,19h
  429.     out    dx,ax
  430.     sti
  431.     pop    dx
  432.     pop    ax
  433.     ret
  434.  
  435. _compaq::            ;Compaq
  436.     push    ax
  437.     push    dx
  438.     push    ax
  439.     cli
  440.     mov    OSEG[curbk],ax
  441.     mov    dx,3ceh
  442.     mov    ax,50fh        ;unlock extended registers
  443.     out    dx,ax
  444.     pop    ax
  445.     mov    ah,al
  446.     mov    al,45h
  447.     out    dx,ax
  448.     sti
  449.     pop    dx
  450.     pop    ax
  451.     ret
  452.  
  453. _s3vga::            ;S3 VGA
  454.     push    ax
  455.     push    dx
  456.     cli
  457.     mov    OSEG[curbk],ax
  458.     sti
  459.     pop    dx
  460.     pop    ax
  461.     ret
  462.  
  463. _vesa::                ;Vesa SVGA interface
  464.     push    ax
  465.     push    bx
  466.     push    cx
  467.     push    dx
  468.     cli
  469.     mov    OSEG[curbk],ax
  470.     mov    dx,ax
  471.     xor    bx,bx
  472.     mov    ax,4f05h
  473.     int    10h
  474.     sti
  475.     pop    dx
  476.     pop    cx
  477.     pop    bx
  478.     pop    ax
  479.     ret
  480.  
  481. _nobank::
  482.     cli
  483.     mov    OSEG[curbk],ax
  484.     sti
  485.     ret
  486.  
  487. newbank    endp
  488.  
  489. bkadr    macro    func
  490.     mov    [func],1
  491.     mov    word ptr [bankadr],offset _&func
  492. if @Codesize
  493.     mov    word ptr [bankadr+2],seg _&func
  494. endif
  495.     endm
  496.  
  497. nojmp    macro
  498.     local    lbl
  499.     jmp    lbl
  500. lbl:
  501.     endm
  502.  
  503.  
  504. whichvga proc    uses si di
  505.     local    vesabuf[256]:byte
  506.  
  507.     cmp    [first],'FI'
  508.     jnz    gotest
  509.     mov    ax,[retval]
  510.     ret
  511. gotest:    mov    word ptr [bankadr],offset _nobank
  512. if @Codesize
  513.     mov    word ptr [bankadr+2],seg _nobank
  514. endif
  515.     mov    [vgamem],256
  516.     mov    [bksize],64
  517.     xor    ax,ax
  518.     mov    [curbk],ax
  519.     mov    [cirrus],ax
  520.     mov    [everex],ax
  521.     mov    [paradise],ax
  522.     mov    [tseng],ax
  523.     mov    [trident],ax
  524.     mov    [t8900],ax
  525.     mov    [ativga],ax
  526.     mov    [aheada],ax
  527.     mov    [aheadb],ax
  528.     mov    [oaktech],ax
  529.     mov    [video7],ax
  530.     mov    [chipstech],ax
  531.     mov    [tseng4],ax
  532.     mov    [genoa],ax
  533.     mov    [ncr],ax
  534.     mov    [compaq],ax
  535.     mov    [s3vga],ax
  536.     mov    [vesa],ax
  537.     mov    [first],'FI'
  538.  
  539.     mov    si,1            ;flag for SVGA found
  540.  
  541.     mov    ax,ss
  542.     mov    es,ax
  543.     lea    di,vesabuf[0]
  544.     mov    ax,4f00h
  545.     int    10h
  546.     cmp    ax,4fh
  547.     jnz    novesa
  548.     bkadr    vesa
  549.     mov    [bksize],64        ; (for now)
  550.  
  551. novesa:    mov    ax,0c000h        ;ATI VGA detect (largely from ATI example code)
  552.     mov    es,ax
  553.     cmp    word ptr es:[40h],'13'    ;ATI Signiture on the Video BIOS
  554.     jnz    noati
  555.     bkadr    ativga
  556.     mov    [bksize],64        ; 64k bank size
  557.     mov    dx,es:[10h]        ; Get value of ATI extended register
  558.     mov    bl,es:[43h]        ; Get value of ATI chip version
  559.     cmp    bl,'3'
  560.     jae    v6up            ; Use different method to determine
  561.     mov    al,0bbh         ; memory size of chip version is 3 or higher
  562.     cli
  563.     out    dx,al
  564.     inc    dx
  565.     in    al,dx            ; Get ramsize byte for chip versions 1 & 2
  566.     sti
  567.     test    al,20h
  568.     jz    no512
  569.     mov    [vgamem],512
  570.     jmp    short no512
  571.  
  572. v6up:    mov    al,0b0h            ; Method used for newer ATI chip versions
  573.     cli
  574.     out    dx,al
  575.     inc    dx
  576.     in    al,dx            ; Get ramsize byte for versions 3-5
  577.     sti
  578.     test    al,10h            ; Check if ramsize byte indicates 256K or 512K bytes
  579.     jz    v7up
  580.     mov    [vgamem],512
  581. v7up:    cmp    bl,'4'            ; Check for ramsize for ATI chip versions 4 & 5
  582.     jb    no512
  583.     test    al,8            ; Check if version 5 ATI chip has 1024K
  584.     jz    no512
  585.     mov    [vgamem],1024
  586. no512:    jmp    fini
  587.  
  588. noati:    mov    ax,7000h        ;Test for Everex
  589.     xor    bx,bx
  590.     cld
  591.     int    10h
  592.     cmp    al,70h
  593.     jnz    noev
  594.     bkadr    everex
  595.     mov    [bksize],64        ; 64k bank size
  596.     and    ch,11000000b        ;how much memory on board
  597.     jz    skp
  598.     mov    [vgamem],512
  599. skp:                    ;fall through for Everex boards using Trident or Tseng4000
  600.  
  601. noev:    mov    ax,0bf03h        ;Test for Compaq
  602.     xor    bx,bx
  603.     mov    cx,bx
  604.     int    10h
  605.     cmp    ax,0bf03h
  606.     jnz    nocp
  607.     test    cl,40h            ;is 640x480x256 available?
  608.     jz    nocp
  609.     bkadr    compaq
  610.     mov    [bksize],4        ; 4k bank size
  611.     mov    [vgamem],512
  612.     jmp    fini
  613.  
  614. nocp:    mov    dx,3c4h            ;Test for NCR 77C22E
  615.     mov    ax,0ff05h
  616.     call    _isport2
  617.     jnz    noncr
  618.     mov    ax,5            ;Disable extended registers
  619.     out    dx,ax
  620.     mov    ax,0ff10h        ;Try to write to extended register 10
  621.     call    _isport2        ;If it writes then not NCR
  622.     jz    noncr
  623.     mov    ax,105h            ;Enable extended registers
  624.     out    dx,ax
  625.     mov    ax,0ff10h
  626.     call    _isport2
  627.     jnz    noncr            ;If it does NOT write then not NCR
  628.     bkadr    ncr
  629.     mov    [bksize],16        ; 16k bank size
  630.     mov    [vgamem],512
  631.     jmp    fini
  632.  
  633. noncr:    mov    dx,3c4h            ;Test for Trident
  634.     mov    al,0bh
  635.     out    dx,al
  636.     inc    dl
  637.     in    al,dx
  638.     and    al,0fh
  639.     cmp    al,06h
  640.     ja    notri
  641.     cmp    al,2
  642.     jb    notri
  643.     bkadr    trident
  644.     mov    [bksize],64        ; 64k bank size
  645.     cmp    al,3
  646.     jb    no89
  647.     mov    [t8900],1
  648.     mov    dx,3d5h
  649.     mov    al,1fh
  650.     out    dx,al
  651.     inc    dx
  652.     in    al,dx
  653.     and    al,3
  654.     cmp    al,1
  655.     jb    notmem
  656.     mov    [vgamem],512
  657.     je    notmem
  658.     mov    [vgamem],1024
  659. notmem:    jmp    fini
  660.  
  661. no89:    mov    [vgamem],512
  662.     jmp    fini
  663.  
  664. notri:    mov    ax,6f00h        ;Test for Video 7
  665.     xor    bx,bx
  666.     cld
  667.     int    10h
  668.     cmp    bx,'V7'
  669.     jnz    nov7
  670.     bkadr    video7
  671.     mov    [bksize],64        ; 64k bank size
  672.     mov    ax,6f07h
  673.     cld
  674.     int    10h
  675.     and    ah,7fh
  676.     cmp    ah,1
  677.     jbe    skp2
  678.     mov    [vgamem],512
  679. skp2:    cmp    ah,3
  680.     jbe    skp3
  681.     mov    [vgamem],1024
  682. skp3:    jmp    fini
  683.  
  684. nov7:    mov    dx,3d4h            ;Test for GENOA GVGA
  685.     mov    ax,032eh        ;check for Herchi Register
  686.     call    _isport2
  687.     jnz    nogn
  688.     mov    dx,3c4h            ;check for memory segment register
  689.     mov    ax,3f06h
  690.     call    _isport2
  691.     jnz    nogn
  692.     bkadr    genoa
  693.     mov    [bksize],64        ; 64k bank size
  694.     mov    [vgamem],512
  695.     jmp    fini
  696.  
  697. nogn:    call    _cirrus            ;Test for Cirrus
  698.     cmp    [cirrus],0
  699.     je    noci
  700.     jmp    fini
  701.  
  702. noci:    mov    dx,3ceh            ;Test for Paradise
  703.     mov    al,9            ;check Bank switch register
  704.     out    dx,al
  705.     inc    dx
  706.     in    al,dx
  707.     dec    dx
  708.     or    al,al
  709.     jnz    nopd
  710.  
  711.     mov    ax,50fh            ;turn off write protect on VGA registers
  712.     out    dx,ax
  713.     mov    dx,offset _paradise
  714.     mov    cx,1
  715.     call    _chkbk
  716.     jc    nopd            ;if bank 0 and 1 same not paradise
  717.     bkadr    paradise
  718.     mov    [bksize],4        ; 4k bank size
  719.     mov    dx,3ceh
  720.     mov    al,0bh            ;512k detect from Bob Berry
  721.     out    dx,al
  722.     inc    dx
  723.     in    al,dx
  724.     test    al,80h            ;if top bit set then 512k
  725.     jz    nop512
  726.     mov    [vgamem],512
  727. nop512:    jmp    fini
  728.  
  729. nopd:    mov    ax,5f00h        ;Test for Chips & Tech
  730.     xor    bx,bx
  731.     cld
  732.     int    10h
  733.     cmp    al,5fh
  734.     jnz    noct
  735.     bkadr    chipstech
  736.     mov    [bksize],16        ; 16k bank size
  737.     cmp    bh,1
  738.     jb    skp4
  739.     mov    [vgamem],512
  740. skp4:    jmp    fini
  741.  
  742. noct:    mov    ch,0
  743.     mov    dx,3d4h            ;check for Tseng 4000 series
  744.     mov    ax,0f33h
  745.     call    _isport2
  746.     jnz    not4
  747.     mov    ch,1
  748.  
  749.     mov    dx,3bfh            ;Enable access to extended registers
  750.     mov    al,3
  751.     out    dx,al
  752.     mov    dx,3d8h
  753.     mov    al,0a0h
  754.     out    dx,al
  755.     jmp    short yes4
  756.  
  757. not4:    mov    dx,3d4h            ;Test for Tseng 3000 or 4000
  758.     mov    ax,1f25h        ;is the Overflow High register there?
  759.     call    _isport2
  760.     jnz    nots
  761.     mov    al,03fh            ;bottom six bits only
  762.     jmp    short yes3
  763. yes4:    mov    al,0ffh
  764. yes3:    mov    dx,3cdh            ;test bank switch register
  765.     call    _isport1
  766.     jnz    nots
  767.     bkadr    tseng
  768.     mov    [bksize],64        ; 64k bank size
  769.     cmp    ch,0
  770.     jnz    t4mem
  771.     mov    [vgamem],512
  772.     jmp    fini
  773.  
  774. t4mem:    mov    dx,3d4h            ;Tseng 4000 memory detect 1meg
  775.     mov    al,37h
  776.     out    dx,al
  777.     inc    dx
  778.     in    al,dx
  779.     test    al,1000b        ;if using 64kx4 RAMs then no more than 256k
  780.     jz    nomem
  781.     and    al,3
  782.     cmp    al,1            ;if 8 bit wide bus then only two 256kx4 RAMs
  783.     jbe    nomem
  784.     mov    [vgamem],512
  785.     cmp    al,2            ;if 16 bit wide bus then four 256kx4 RAMs
  786.     je    nomem
  787.     mov    [vgamem],1024        ;full meg with eight 256kx4 RAMs
  788. nomem:    bkadr    tseng4
  789.     mov    [bksize],64        ; 64k bank size
  790.     jmp    fini
  791.  
  792. nots:    mov    dx,3ceh            ;Test for Above A or B chipsets
  793.     mov    ax,200fh
  794.     out    dx,ax
  795.     inc    dx
  796.     nojmp
  797.     in    al,dx
  798.     cmp    al,21h
  799.     jz    verb
  800.     cmp    al,20h
  801.     jnz    noab
  802.     bkadr    aheada
  803.     mov    [bksize],64        ; 64k bank size
  804.     mov    [vgamem],512
  805.     jmp    fini
  806.  
  807. verb:    bkadr    aheadb
  808.     mov    [bksize],64        ; 64k bank size
  809.     mov    [vgamem],512
  810.     jmp    fini
  811.  
  812. noab:    mov    dx,3c4h            ;Test for AcuMos chipsets
  813.     mov    ax,0006h        ;disable extended registers
  814.     out    dx,ax
  815.     mov    ax,0ff09h
  816.     call    _isport2        ;is scratchpad at index 9 writeable ?
  817.     jz    noacu
  818.     mov    ax,0ff0ah
  819.     call    _isport2        ;is scratchpad at index 10 writable ?
  820.     jz    noacu
  821.     mov    ax,1206h
  822.     out    dx,ax
  823.     mov    ax,0ff09h
  824.     call    _isport2
  825.     jnz    noacu
  826.     mov    ax,0ff0ah
  827.     call    _isport2
  828.     jnz    noacu
  829.     mov    dx,offset _acumos
  830.     mov    cx,1
  831.     call    _chkbk
  832.     jc    noacu            ;if bank 0 and 1 same not acumos
  833.     bkadr    acumos
  834.     mov    [bksize],4        ; 4k bank size
  835.     mov    dx,3c4h
  836.     mov    al,0ah
  837.     out    dx,al
  838.     inc    dx
  839.     in    al,dx            ;get scratchpad index 10
  840.     and    al,3
  841.     cmp    al,1
  842.     jb    noamem
  843.     mov    [vgamem],512
  844.     cmp    al,2
  845.     jb    noamem
  846.     mov    [vgamem],1024
  847.     cmp    al,3
  848.     jb    noamem
  849.     mov    [vgamem],2048
  850. noamem:    jmp    short fini
  851.  
  852. noacu:    mov    dx,3deh            ;Test for Oak Technology
  853.     mov    ax,0ff11h        ;look for bank switch register
  854.     call    _isport2
  855.     jnz    nooak
  856.     bkadr    oaktech
  857.     mov    [bksize],64        ; 64k bank size
  858.     mov    al,0dh
  859.     out    dx,al
  860.     inc    dx
  861.     nojmp
  862.     in    al,dx
  863.     test    al,11000000b
  864.     jz    no4ram
  865.     mov    [vgamem],512
  866.     test    al,01000000b
  867.     jz    no4ram
  868.     mov    [vgamem],1024
  869. no4ram:    jmp    short fini
  870.  
  871. nooak:    jmp    short nos3
  872.     bkadr    s3vga
  873.     mov    [bksize],64        ; 64k bank size
  874.     mov    [vgamem],1024
  875.     jmp    short fini
  876.  
  877. nos3:    cmp    [vesa],0
  878.     jz    nosvga
  879.     mov    [vgamem],2048
  880.     jmp    short fini
  881.  
  882. nosvga:    mov    si,0
  883.  
  884. fini:    mov    ax,si
  885.     mov    [retval],ax
  886.     ret
  887. whichvga endp
  888.  
  889.  
  890. _cirrus    proc    near
  891.     mov    dx,3d4h        ; assume 3dx addressing
  892.     mov    al,0ch        ; screen a start address hi
  893.     out    dx,al        ; select index
  894.     inc    dx        ; point to data
  895.     mov    ah,al        ; save index in ah
  896.     in    al,dx        ; get screen a start address hi
  897.     xchg    ah,al        ; swap index and data
  898.     push    ax        ; save old value
  899.     push    dx        ; save crtc address
  900.     xor    al,al        ; clear crc
  901.     out    dx,al        ; and out to the crtc
  902.  
  903.     mov    al,1fh        ; Eagle ID register
  904.     dec    dx        ; back to index
  905.     out    dx,al        ; select index
  906.     inc    dx        ; point to data
  907.     in    al,dx        ; read the id register
  908.     mov    bh,al        ; and save it in bh
  909.  
  910.     mov    cl,4        ; nibble swap rotate count
  911.     mov    dx,3c4h        ; sequencer/extensions
  912.     mov    bl,6        ; extensions enable register
  913.  
  914.     ror    bh,cl        ; compute extensions disable value
  915.     mov    ax,bx        ; extensions disable
  916.     out    dx,ax        ; disable extensions
  917.     inc    dx        ; point to data
  918.     in    al,dx        ; read enable flag
  919.     or    al,al        ; disabled ?
  920.     jnz    exit        ; nope, not an cirrus
  921.  
  922.     ror    bh,cl        ; compute extensions enable value
  923.     dec    dx        ; point to index
  924.     mov    ax,bx        ; extensions enable
  925.     out    dx,ax        ; enable extensions
  926.     inc    dx        ; point to data
  927.     in    al,dx        ; read enable flag
  928.     cmp    al,1        ; enabled ?
  929.     jne    exit        ; nope, not an cirrus
  930.     mov    [cirrus],1
  931.     mov    word ptr [bankadr],offset _nobank
  932. if @Codesize
  933.     mov    word ptr [bankadr+2],seg _nobank
  934. endif
  935. exit:    pop    dx        ; restore crtc address
  936.     dec    dx        ; point to index
  937.     pop    ax        ; recover crc index and data
  938.     out    dx,ax        ; restore crc value
  939.     ret
  940. _cirrus    endp
  941.  
  942. _chkbk    proc    near        ;bank switch check routine
  943.     mov    di,0b800h
  944.     mov    es,di
  945.     xor    di,di
  946.     mov    bx,1234h
  947.     call    _gochk
  948.     jnz    badchk
  949.     mov    bx,4321h
  950.     call    _gochk
  951.     jnz    badchk
  952.     clc
  953.     ret
  954. badchk:    stc
  955.     ret
  956. _chkbk    endp
  957.  
  958. calldx    macro
  959. if @Codesize
  960.     push    cs
  961. endif
  962.     call    dx
  963.     endm
  964.  
  965. _gochk    proc    near
  966.     push    si
  967.     mov    si,bx
  968.  
  969.     mov    al,cl
  970.     calldx
  971.     xchg    bl,es:[di]
  972.     mov    al,ch
  973.     calldx
  974.     xchg    bh,es:[di]
  975.  
  976.     xchg    si,bx
  977.  
  978.     mov    al,cl
  979.     calldx
  980.     xor    bl,es:[di]
  981.     mov    al,ch
  982.     calldx
  983.     xor    bh,es:[di]
  984.  
  985.     xchg    si,bx
  986.  
  987.     mov    al,ch
  988.     calldx
  989.     mov    es:[di],bh
  990.     mov    al,cl
  991.     calldx
  992.     mov    es:[di],bl
  993.  
  994.     mov    al,0
  995.     calldx
  996.     or    si,si
  997.     pop    si
  998.     ret
  999. _gochk    endp
  1000.  
  1001. _isport2 proc    near        ;check for valid indexed i/o port, al is index, ah is bit mask
  1002.     push    bx
  1003.     mov    bx,ax
  1004.     out    dx,al
  1005.     mov    ah,al
  1006.     inc    dx
  1007.     in    al,dx
  1008.     dec    dx
  1009.     xchg    al,ah
  1010.     push    ax
  1011.     mov    ax,bx
  1012.     out    dx,ax
  1013.     out    dx,al
  1014.     mov    ah,al
  1015.     inc    dx
  1016.     in    al,dx
  1017.     dec    dx
  1018.     and    al,bh
  1019.     cmp    al,bh
  1020.     jnz    noport
  1021.     mov    al,ah
  1022.     mov    ah,0
  1023.     out    dx,ax
  1024.     out    dx,al
  1025.     mov    ah,al
  1026.     inc    dx
  1027.     in    al,dx
  1028.     dec    dx
  1029.     and    al,bh
  1030.     cmp    al,0
  1031. noport:    pop    ax
  1032.     out    dx,ax
  1033.     pop    bx
  1034.     ret
  1035. _isport2 endp
  1036.  
  1037. _isport1 proc    near        ;check for valid i/o port, al is bit mask
  1038.     mov    ah,al
  1039.     in    al,dx
  1040.     push    ax
  1041.     mov    al,ah
  1042.     out    dx,al
  1043.     in    al,dx
  1044.     and    al,ah
  1045.     cmp    al,ah
  1046.     jnz    noport
  1047.     mov    al,0
  1048.     out    dx,al
  1049.     in    al,dx
  1050.     and    al,ah
  1051.     cmp    al,0
  1052. noport:    pop    ax
  1053.     out    dx,al
  1054.     ret
  1055. _isport1 endp
  1056.  
  1057.     end
  1058.  
  1059.